home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d7 / asycls10.arc / SPDTERM.CPP < prev   
C/C++ Source or Header  |  1991-04-28  |  2KB  |  85 lines

  1. /* A terminal program which I wrote to practice programming in C++ */
  2.  
  3. #include <conio.h>
  4. #include <iostream.h>
  5. #include <stdio.h>
  6.  
  7. #include "spdterm.h"        // structures and global vars and defines
  8. #include "asynch.h"         // Asynch class definition
  9.  
  10.  
  11. static Asynch com2(COM2,2400);
  12.  
  13.  
  14. inline char readch()
  15. {
  16.     if (kbhit())
  17.     {
  18.         char ch = getch();
  19.         if (!ch)
  20.         {
  21.             if (getch()==45)    // Alt-X hit
  22.                 return(-1);
  23.         }
  24.         return(ch);
  25.     }
  26.     return(0);
  27. }
  28.  
  29.  
  30. inline void writech(char ch)
  31. {
  32.     if (ch)
  33.         cout << ch;
  34. }
  35.  
  36.  
  37. void terminal(void)
  38. {
  39.     clrscr();
  40.     cout << "Terminal ready... hit Alt-X to exit.\n";
  41.     char modem=0,key=0;
  42.     int done=0;
  43.     do {
  44.         key=readch();
  45.         switch(key) {
  46.             case -1: // exit terminal
  47.                 done=1;
  48.                 break;
  49.             default:
  50.                 break;
  51.         }
  52.         com2 << key;
  53.         com2 >> modem;
  54.         writech(modem);
  55.     } while (!done);
  56. }
  57.  
  58.  
  59. void answer(void)
  60. {
  61.     cout << "Waiting for call... ";
  62.     while(!com2.inCount() && !kbhit())
  63.         ;
  64.     char s[81];
  65.     int i=0;
  66.     while(com2.inCount())
  67.         com2 >> s[i++];
  68.     s[i]=0;
  69.     cout << s;
  70.     com2 << "ata\r";
  71. }
  72.  
  73.  
  74. #define INIT_STR    "AT Z"
  75. void main()
  76. {
  77.     com2 << INIT_STR << '\r';
  78.     com2.flushAllBufs();
  79. //    if (!com2.dtr())  // not really necessary
  80. //        com2.setDtr();
  81.     terminal();
  82. //    answer();     // still doesn't work right
  83. //    com2.dropDtr();
  84. }
  85.